package com.eastcode.base.util;

import java.util.Date;

public class ObjectUtil {

	/**
	 * 转化参数
	 * 
	 * @param cls
	 * @param param
	 * @return
	 */
	public static Object convert(Class<?> cls, String param) {
		// 类型判断
		if (cls.isAssignableFrom(Date.class)) {
			return DateUtil.parseDateTime(param);
		} else if (cls.isAssignableFrom(int.class)) {
			return Integer.parseInt(param);
		} else if (cls.isAssignableFrom(long.class)) {
			return Long.parseLong(param);
		} else if (cls.isAssignableFrom(float.class)) {
			return Float.parseFloat(param);
		} else if (cls.isAssignableFrom(boolean.class)) {
			return Boolean.parseBoolean(param);
		} else if (cls.isAssignableFrom(double.class)) {
			return Double.parseDouble(param);
		} else if (cls.isAssignableFrom(byte.class)) {
			return Byte.parseByte(param);
		}

		return param;
	}
}
